package com.maserb.monitor.entity.card;

import com.maserb.monitor.entity.BaseIdEntity;
import com.maserb.monitor.entity.schoolStudent.SchoolStudentEntity;
import lombok.Data;

import javax.persistence.*;

@Deprecated
@Entity
@Table(name = "attendance_card_record")
public class CardRecordEntity extends BaseIdEntity {

    private String cardNumber;
    private String date;
    private String time;
    private Integer state;

    private SchoolStudentEntity student;

    @Transient
    public static CardRecordEntity convert(String sequence, Box<Integer> index) {
        CardRecordEntity entity = new CardRecordEntity();
        entity.setCardNumber(CardUtils.get(sequence, index,8));
        entity.setDate(CardUtils.get(sequence, index, 6));
        entity.setTime(CardUtils.get(sequence, index, 6));
        entity.setState(Integer.valueOf(CardUtils.get(sequence, index, 1)));
        return entity;
    }

    @Column(name = "card_number", length = 50)
    public String getCardNumber() {
        return cardNumber;
    }

    public void setCardNumber(String cardNumber) {
        this.cardNumber = cardNumber;
    }

    @Column(name = "date", length = 10)
    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    @Column(name = "time", length = 10)
    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    @Column(name = "state")
    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "student_id")
    public SchoolStudentEntity getStudent() {
        return student;
    }

    public void setStudent(SchoolStudentEntity student) {
        this.student = student;
    }
}
